<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>表单列表渲染</title>
<{$showjs}>
<link rel="stylesheet" type="text/css" href="/css/main.css" />
<script type="text/javascript" src="/Plug-in/ext/Ext.grid.CheckColumn.js"></script>
<script type="text/javascript" src="/Plug-in/ext/Ext.Store.Sort.js"></script>
<script type="text/javascript" src="/Plug-in/ext/Ext.form.Property.js"></script>
<style type="text/css">
.add{background:url(/img/add.gif) no-repeat 1px 2px !important;}
.copy{background:url(/img/copy.gif) no-repeat 1px 2px !important;}
.del{background:url(/img/del.gif) no-repeat 1px 2px !important;}
.edit{background:url(/img/edit.gif) no-repeat 1px 2px !important;}
.search{background:url(/img/find.gif) no-repeat 1px 2px !important;}
.hidea{background:url(/img/arrow_out.png) no-repeat 1px 2px !important;}
</style>
<script language="javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

function edit_handler(){
	if(grid.selModel.getCount()==1){
		var selections = grid.selModel.getSelections();
		var param =selections[0].data;
		parent.xajax_loadUrl('<{$tree.title}>','renderer/form_render.php?require=edit~add&id='+param.id+'&tree_id=<{$id}>',1000,500,false);
	}else if(grid.selModel.getCount()>1){
		Ext.MessageBox.alert("提示","本操作无法批量完成");
	}else{
 		Ext.Msg.alert("提示消息","请选择一行数据然后才能编辑!");return false;
	}
}
function del_handler(){
	var selections = grid.selModel.getSelections();
		var param =selections[0].data;
		myMask.show();
		Ext.Ajax.request(
			{
				waitMsg:'正在提交....',
				method:'POST',
				params:{require:'del_item',id:param.id,tree_id:<{$id}>},
				url:'form_render.php',
				success:function(form, action) {
					ds.reload();
					myMask.hide();
				},
				failure: function(form, action) {
			}
		}
		);
}
function add_handler(){
	parent.xajax_loadUrl('<{$tree.title}>',"renderer/form_render.php?require=edit~add&id=0&tree_id=<{$id}>",1000,500,false);
}
	var myMask = new Ext.LoadMask(Ext.getBody(), {
                        msg: '请稍候...',
                        removeMask: true
                    });
	 var checkColumn = new Ext.grid.CheckColumn({
       header: "Indoor",
       dataIndex: 'indoor',
       width: 55
    });
    var sm = new Ext.grid.CheckboxSelectionModel();
    var data = {url : "form_render.php" , method:'POST'};
    var requestParams = {require:'list_data',id:'<{$id}>'};
	var cmCfg = [
					sm,
					{id:'id',header:'ID',dataIndex:'id', width: 40,sortable:true,readOnly:true},
					<{section name=li loop=$config}>
					{id:'<{$config[li].id}>',header:'<{$config[li].name}>',dataIndex:'<{$config[li].field_name}>',width:<{$config[li].list_width}>,sortable:true<{if $config[li].renderer neq ''}><{$config[li].renderer}><{/if}>}
					<{if $smarty.section.li.index+1 < $config|@count}>,<{/if}>
					<{/section}>
				];
	var robj = [
			new Ext.grid.RowNumberer(),
            {name: 'id'},
            <{section name=li loop=$config}>
					{name:'<{$config[li].field_name}>'}
			<{if $smarty.section.li.index+1 < $config|@count}>,<{/if}>
			<{/section}>
        ];
    var rd = new Ext.data.JsonReader({
		totalProperty:'total',
		root:'data',
		id:'jsonreader'
	},robj);
	var ds = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy(data),
		reader:rd,
		baseParams:requestParams,
		sortInfo:{field :'id',direction:'ASC'}
	});
	var cm = new Ext.grid.ColumnModel(cmCfg);

	var grid = new Ext.grid.GridPanel({
		id:'cms-grid-id',
		renderTo:Ext.getBody(),
		width:parent.Ext.get('cms-center').getWidth()-2,
		//region:'center',
		clicksToEdit:1,
		ds:ds,
		cm:cm,
		sm:sm,
		tbar: [
			'->',
			'-',
			{text:'高级d搜索',iconCls:'search',tooltip:'高级搜索'},
			'-',
			<{if $tree.shield_edit neq 1}>{text:'编辑',iconCls:'edit',handler:edit_handler},
			'-',<{/if}>
			<{if $tree.shield_add neq 1}>{text:'添加',iconCls:'add',handler:add_handler},
			'-',<{/if}>
			<{if $tree.shield_del neq 1}>{text:'删除',iconCls:'del',handler:del_handler},
			'-',<{/if}>
			{text:'最大化',iconCls:'hidea',handler:function (){
					window.top.west.collapse(true);
					window.top.north.collapse(true);

			}},
			'-'
		],
		bbar: new Ext.PagingToolbar({
			pageSize: 20,
			store: ds,
			displayInfo: true,
			displayMsg: '显示第 {0} 条到 {1} 条记录，总共 {2} 条',
			emptyMsg: "没有记录"
		}),
		//autoWidth:true,
		height:parent.Ext.get('cms-center').getHeight()-30,
		autoShow:true,
		frame:false,
		autoDestroy:true,
		title:false,
		border:true,
		loadMask:{msg:"正在加载数据..."}
	});
	ds.load({params:{start:0,limit:20}});
	grid.on('columnresize',function(columnIndex,newSize){
		var column_id=cm.getColumnId(columnIndex);
		myMask.show();
		Ext.Ajax.request(
					                {
					                    waitMsg:'正在提交....',
					                    method:'POST',
					                    params:{require:'width_change',id:column_id,width:newSize},
					                    url:'form_render.php',
					                    success:function(form, action) {
											myMask.hide();
					                    },
					                    failure: function(form, action) {
					                    }
					                }
					            );
	});
parent.gridrefresh = function(){
	ds.reload();
}
	});
</script>
</head>
<body>
<div id='grid'></div>
</body>
</html>